<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of promos_,model
 *
 * @author daw
 */
class Promos_model extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    public function insert($arr_insert) {
        $this->db->insert('promociones_pelicula', $arr_insert);
    }

    public function get_promos($slug = FALSE) {
        if ($slug === FALSE) {
            $query = $this->db->get('promociones_pelicula');      
            $aux = $query->result_array();
            for ($i = 0; $i < count($aux); $i++) {
                $aux[$i]['cod_pelicula'] = $this->get_titulo_dist($aux[$i]['cod_pelicula']);
            }
            return $aux;
        }
        $query = $this->db->get_where('promociones_pelicula', array('cod_pelicula' => $slug));
        return $query->result_array();
    }

    public function get_promos_sala($slug = FALSE) {
        if ($slug === FALSE) {
            $query = $this->db->get('promociones_sala');
            //Returnarray devuelve toods los resultados
            return $query->result_array();
        }
        $query = $this->db->get_where('promociones_sala', array('cod_pelicula' => $slug));
        return $query->row_array();
    }

    public function get_titulo_dist($aux ) {

        $resultado = $query = $this->db->get_where('peliculas', array('cod_pelicula' => $aux));
        $data = $resultado->row_array();
        return $data['titulo_dist'];
    }
}
